package com.pure.common.lambda.impl;

import com.pure.common.lambda.TestInterfaceI;
import lombok.Data;
import lombok.ToString;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @description: test lambda class
 * @author: Jeffrey
 * @created: 2022-05-09 22:33
 **/
public class TestInterfaceImpl implements TestInterfaceI {
    @Override
    public void testMethod() {

        System.out.println("接口实现类重写抽象方法...");
    }

    @Data
    @ToString
    public static class Operator {
        private String name;
        private Long customer;
        private Integer age;
    }

    public static void main(String[] args) {

        List<Operator> arrays = new ArrayList<>();
        List<Operator> remove = new ArrayList<>();
        List<Operator> age = new ArrayList<>();
        Operator operator = null;
        for (int i = 1; i <= 10; i++) {
            operator = new Operator();
            operator.setName("name" + i);
            operator.setCustomer(Long.valueOf(i));
            operator.setAge(i);

            if(i <= 8) {
                age.add(operator);
            }

            if (i <= 5) {
                remove.add(operator);
            }

            arrays.add(operator);
        }

        ArrayList<List<Operator>> totalArras = new ArrayList<>();
        totalArras.add(arrays);
        totalArras.add(remove);
        totalArras.add(age);

        System.out.println(totalArras.toString());

        List<Operator> unionSet = totalArras.stream().flatMap(Collection::stream).collect(Collectors.toList());
        System.out.println(unionSet.toString());
        List<String> nameSet = unionSet.stream().map(Operator::getName).distinct().collect(Collectors.toList());
        List<Long> customerSet = unionSet.stream().map(Operator::getCustomer).distinct().collect(Collectors.toList());
        List<Integer> ageSet = unionSet.stream().map(Operator::getAge).distinct().collect(Collectors.toList());
        System.out.println(nameSet.toString());
        System.out.println(customerSet.toString());
        System.out.println(ageSet.toString());

//        System.out.println(arrays.toString());
//        System.out.println(remove.toString());
//        List<String> containsName = remove.stream().map(Operator::getName).collect(Collectors.toList());
//        List<Integer> containsAge = age.stream().map(Operator::getAge).collect(Collectors.toList());
//        System.out.println(containsName.toString());
//        System.out.println(containsAge.toString());
//        List<Operator> collect = arrays.stream()
//                .filter(o -> containsName.contains(o.getName()) && containsAge.contains(o.getAge())).collect(Collectors.toList());
//        System.out.println(collect.toString());

//        if (arrays.removeAll(remove)){
//            System.out.println(arrays.toString());
//        }


//        HashMap<String, Integer> map = new HashMap<>();
//        map.put("dog", 10000);
//        Set<Map.Entry<String, Integer>> mapEntries = map.entrySet();
//        for (Map.Entry<String, Integer> mapEntry : mapEntries) {
//            String key = mapEntry.getKey();
//            Integer value = mapEntry.getValue();
//            System.out.println("key = " + key + ", value = " + value);
//        }
    }
}


